//
//  EmoticonViewModel.swift
//  02-表情键盘
//
//  Created by  NorthCity on 15/11/13.
//  Copyright © 2015年  NorthCity. All rights reserved.
//

import Foundation
class EmoticonManager{
//    单例
    static let sharedManager = EmoticonManager()
//    表情包数据
    lazy var packages = [EmoticonPackage]()
//    构造函数
   private init(){
//    0 添加 最近分组
       packages.append(EmoticonPackage(dict:["group_name_cn":"最近"]))
//    1 emoticon.plist 的路径
        guard let path = NSBundle.mainBundle().pathForResource("emoticons", ofType: "plist",inDirectory: "Emoticons.bundle")else{
            print("文件不存在")
            return
        }
//    2 获取字典
        guard let dict = NSDictionary(contentsOfFile: path) else{
            print("数据加载错误")
            return
        }
//    3 获取 package 中 id 对应数组
        let array = (dict["packages"] as! NSArray).valueForKey("id") as! [String]
//    4 遍历数组字典转模型
        for id in array {
            loadPlistInfo(id)
        }
    }
    
        private func loadPlistInfo(id:String){

//           1 创建路径
            let path = NSBundle.mainBundle().pathForResource("info", ofType: "plist",inDirectory: "Emoticons.bundle/\(id)")!
//           2 加载字典
            let dict = NSDictionary(contentsOfFile: path) as![String:AnyObject]
//           3 字典转模型
            packages.append(EmoticonPackage(dict: dict))
            
            
        }

}